﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// ToolBarWindow.xaml 的交互逻辑
    /// </summary>
    public partial class ToolBarWindow : Window
    {
        public ToolBarWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        ///  选择事件
        /// 如果嵌套的触发 sender就可能是ToolBarWindow
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            //如果嵌套的触发 sender就可能是ToolBarWindow
            RadioButton radioButton = !(sender is ToolBarWindow)? sender as RadioButton : e.OriginalSource as RadioButton;

            ItemCollection items = toolBar1.Items;
            foreach (var item in items)
            {
                if (item is RadioButton && (item as RadioButton).GroupName == "radioButtonGroup" && (item as RadioButton).ToolTip != radioButton.ToolTip)
                {
                    ((item as RadioButton).Content as Rectangle).Opacity = 1;
                }
            }

            if (radioButton.Content != null)
            {
                (radioButton.Content as Rectangle).Opacity = 0.5;
                 labelTxt.Foreground = (radioButton.Content as Rectangle).Fill;
            }
            else
            {
                Color color = GetColor(radioButton.ToolTip.ToString());
                labelTxt.Foreground = new SolidColorBrush(color);
            }
     
            Console.WriteLine("");
        }

        /// <summary>
        /// 获取颜色
        /// </summary>
        /// <param name="colorKey"></param>
        /// <returns></returns>
        private Color GetColor(string colorKey)
        {
            Color color;
            switch (colorKey)
            {
                case "Red":
                    color= Colors.Red;
                    break;
                case "Green":
                    color = Colors.Green;
                    break;
                case "Yellow":
                    color = Colors.Yellow;
                    break;
                case "Wheat":
                    color = Colors.Wheat;
                    break;
                default:
                    color = Colors.Black;
                    break;
            }
            return color;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            //ItemCollection items = toolBar1.Items;
            //foreach (var item in items)
            //{
            //    if (item is RadioButton && (item as RadioButton).GroupName == "radioButtonGroup" && (item as RadioButton).IsChecked.HasValue)
            //    {
            //        Console.WriteLine((item as RadioButton).ToolTip.ToString());
            //        labelTxt.Foreground = ((item as RadioButton).Content as Rectangle).Fill;
            //    }
            //}
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Window w = new Window();
            w.Show();
        }

        private void ComboBoxItem_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Window w = new Window();
            w.Show();
        }
    }
}
